package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.AdSensitivePageRequestDto;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.mapper.AdChannelMapper;
import com.itheima.admin.mapper.AdSensitiveMapper;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.pojo.AdSensitive;
import com.itheima.admin.service.AdChannelService;
import com.itheima.admin.service.AdSensitiveService;
import com.itheima.common.vo.PageResultVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @version 1.0
 * @description 说明
 * @package com.itheima.admin.service.impl
 *
 * ServiceImpl<AdChannelMapper, AdChannel> mybatis plus封装业务层操作，CRUD，分页.
 */
@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {


    /**
     * 频道分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageResultVo findPage(AdSensitivePageRequestDto dto) {
        //1. 设置分页参数
        //【注意】，第一个参数为页码，第二个参数为大小
        IPage<AdSensitive> pageInfo = new Page<>(dto.getPage(), dto.getSize());
        //2. 构建查询条件
        LambdaQueryWrapper<AdSensitive> lqw = new LambdaQueryWrapper<>();
        // name有值，则使用模糊查询, 选中方法Ctrl+B看方法源码
        // 【注意】不要漏了 感叹号
        lqw.like(!StringUtils.isEmpty(dto.getName()), AdSensitive::getSensitives, dto.getName());
        //3. 查询
        IPage<AdSensitive> pageResult = page(pageInfo, lqw);
        // 问题 pageResult==pageInfo? 堆中地址 为什么相等?
        System.err.println("pageResult == pageInfo? => " + (pageResult == pageInfo));
        //4. 构建分页结果
        PageResultVo<AdSensitive> vo = PageResultVo.pageResult(dto.getPage(), dto.getSize(), pageInfo.getTotal(), pageInfo.getRecords());
        //5. 返回数据
        return vo;
    }
}
